'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 检查并添加平台来源字段
    try {
      await queryInterface.addColumn('sales_orders', 'platform_source', {
        type: Sequelize.STRING(50),
        allowNull: true,
        comment: '平台来源'
      });
    } catch (error) {
      console.log('平台来源字段可能已存在:', error.message);
    }

    // 检查并添加是否含赠品字段
    try {
      await queryInterface.addColumn('sales_orders', 'is_gift', {
        type: Sequelize.BOOLEAN,
        defaultValue: false,
        comment: '是否含赠品'
      });
    } catch (error) {
      console.log('是否含赠品字段可能已存在:', error.message);
    }
  },

  down: async (queryInterface, Sequelize) => {
    // 删除平台来源字段
    try {
      await queryInterface.removeColumn('sales_orders', 'platform_source');
    } catch (error) {
      console.log('删除平台来源字段时出错:', error.message);
    }
    
    // 删除是否含赠品字段
    try {
      await queryInterface.removeColumn('sales_orders', 'is_gift');
    } catch (error) {
      console.log('删除是否含赠品字段时出错:', error.message);
    }
  }
};